package org.groupg.practice.collections.Comparator;

import org.apache.commons.text.diff.CommandVisitor;
import org.apache.commons.text.diff.EditScript;
import org.apache.commons.text.diff.StringsComparator;

import java.util.Arrays;
import java.util.List;

public class ComparatorDemo {
    public static void main(String[] args) {
        String oldStr = "abcde";
        String newStr = "aefgh";
// 创建比较器
        StringsComparator comparator = new StringsComparator(oldStr, newStr);

// 生成编辑脚本
        EditScript<Character> script = comparator.getScript();

// 遍历操作指令
        script.visit(new CommandVisitor<Character>() {
            @Override
            public void visitInsertCommand(Character c) {
                System.out.println("插入字符: " + c);
            }

            @Override
            public void visitDeleteCommand(Character c) {
                System.out.println("删除字符: " + c);
            }

            @Override
            public void visitKeepCommand(Character c) {
                // 保留字符不处理
            }
        });

        List<Integer> oldList = Arrays.asList(1, 2, 3);
        List<Integer> newList = Arrays.asList(2, 4, 5);

//// 创建比较器
//        ListComparator<Integer> comparator = new ListComparator<>(oldList, newList);
//
//// 生成编辑脚本
//        EditScript<Integer> script = comparator.getScript();
//
//        script.visit(new CommandVisitor<Integer>() {
//            @Override
//            public void visitInsertCommand(Integer num) {
//                System.out.println("插入数字: " + num);
//            }
//
//            @Override
//            public void visitDeleteCommand(Integer num) {
//                System.out.println("删除数字: " + num);
//            }
//
//            @Override
//            public void visitKeepCommand(Integer num) {
//            }
//        });
    }
}
